using MicroMsg.Common.Utils;
using MicroMsg.Scene;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace MicroMsg.Manager
{
	public class EggProfileMgr
	{
		private const string TAG = "EggProfileMgr";
		public static EggItemList parasEggProfileXml(string strXml)
		{
			if (string.IsNullOrEmpty(strXml))
			{
				return null;
			}
			if (!strXml.StartsWith("<"))
			{
				int num = strXml.IndexOf("<", 0);
				strXml = strXml.Substring(num);
			}
			if (string.IsNullOrEmpty(strXml))
			{
				return null;
			}
			EggItemList result;
			try
			{
				EggItemList eggItemList = null;
				XDocument xDocument = XDocument.Parse(strXml);
				XElement xElement = xDocument.Element("EasterEgg");
				if (xElement == null)
				{
					result = null;
				}
				else
				{
					if (eggItemList == null)
					{
						eggItemList = new EggItemList();
					}
					eggItemList.version = xElement.Attribute("version").get_Value();
					IEnumerable<XElement> enumerable = xElement.Elements();
					using (IEnumerator<XElement> enumerator = enumerable.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							XElement current = enumerator.get_Current();
							if (current != null)
							{
								EggItem eggItem = new EggItem();
								eggItem.name = current.Attribute("name").get_Value();
								eggItem.reportType = current.Attribute("reportType").get_Value();
								XElement xElement2 = current.Element("KeyWord");
								if (xElement2 != null)
								{
									eggItem.KeyWord = xElement2.get_Value();
								}
								XElement xElement3 = current.Element("Emoji");
								if (xElement3 != null)
								{
									string value = xElement3.get_Value();
									eggItem.emoji = NetSceneGetPackageList.decodeBase64("UTF-8", value);
								}
								eggItemList.eggList.Add(eggItem);
							}
						}
					}
					eggItemList.lastUpdateTime = Util.getNowMilliseconds();
					result = eggItemList;
				}
			}
			catch (Exception ex)
			{
				Log.smethod_1("EggProfileMgr", ex.get_Message());
				result = null;
			}
			return result;
		}
		public static void saveEggProfile(EggItemList egglist)
		{
			ConfigMgr.write<EggItemList>(egglist);
		}
		public static EggItemList getEggProfile()
		{
			EggItemList eggItemList = ConfigMgr.read<EggItemList>();
			if (eggItemList != null && eggItemList.eggList.get_Count() > 0)
			{
				return eggItemList;
			}
			GetPackageListMgr.getPackageList(6);
			return null;
		}
	}
}
